package com.lm.csv.example;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;

import java.io.StringReader;

public class SpecialCharacterExample {
    public static void main(String[] args) throws Exception {
        String csvData = "ID,Name,Notes\n" +
                "1,\"John\",\"Loves coding\nand teaching\"\n" +
                "2,\"Jane\",\"Enjoys reading\"";

        try (CSVParser parser = CSVFormat.DEFAULT
                .withFirstRecordAsHeader()
                .parse(new StringReader(csvData))) {

            parser.forEach(record -> {
                String id = record.get("ID");
                String name = record.get("Name");
                String notes = record.get("Notes");

                System.out.printf("ID: %s, Name: %s, Notes: %s%n", id, name, notes);
            });
        }
    }
}
